<?php
/**
 * Created by PhpStorm.
 * User: ownfi
 * Date: 2017-03-20
 * Time: 15:26
 */

namespace App\Services\Impl;


use App\Common\Constant\CacheKey;
use App\Models\Master;
use App\Services\ICacheService;
use Cache;

class CacheServiceImpl implements ICacheService
{
    public function smsVerifyCode($phoneNum, $verifyCode = null, $minutes = 5)
    {
        $cacheKey = CacheKey::smsVerifyKey($phoneNum);
        if ($verifyCode === null){
            return Cache::get($cacheKey);
        }else{
            Cache::put($cacheKey, $verifyCode, $minutes);
            return Cache::has($cacheKey);
        }
    }

    public function currentUser($weixinUserid, Master $user = null, $minutes = 1440)
    {
        $cacheKey = CacheKey::currentUserKey($weixinUserid);
        if ($user === null){
            return Cache::get($cacheKey);
        }else{
            Cache::put($cacheKey, $user, $minutes);
            return Cache::has($cacheKey);
        }
    }

}